package com.lms.logisticsmanagementsystem.service.Impl;

import com.lms.logisticsmanagementsystem.mapper.StaffMapper;
import com.lms.logisticsmanagementsystem.model.Staff;
import com.lms.logisticsmanagementsystem.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StaffServiceImpl implements StaffService{

    @Autowired
    private StaffMapper staffMapper;

    /*
        添加员工
     */
    @Override
    public boolean addStaff(Staff staff) {
        //添加数据，添加成功，返回1
        Integer add = staffMapper.addStaff(staff);
        if (add==1){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<Staff> getStaffInfo() {
        List<Staff> staffList = staffMapper.getStaffList();
        for (Staff staff:staffList){
            if (staff.getSex().equals("1")){
                staff.setSex("男");
            }
            if (staff.getSex().equals("0")){
                staff.setSex("女");
            }
        }
        return staffList;
    }

    @Override
    public Staff getStaffInfoById(String id) {
        Staff staff = staffMapper.getStaffInfoById(id);
        return staff;
    }

    @Override
    public boolean updateStaffInfoById(Staff staff) {
        Integer update = staffMapper.updateStaffInfoById(staff);
        if (update==1){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean delStaffInfoById(Integer id) {
        Integer flag = staffMapper.delStaffInfoById(id);
        if (flag==1){
            return true;
        }else {
            return false;
        }
    }
}
